<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			// 父类(Person)
			class Person {
				// 默认在公有上，实例初始化(增加私有属性)
				constructor(name, age) {
					console.log(name, age);
					// 增加私有
					// this->自动帮我们创建那个对象（实例）
					this.name = name;
					this.age = age;
				};

				// 增加公有
				say() {
					console.log(`我叫${this.name},我今年${this.age}岁~~~`);
				}
			}

			// 子类（Student） 
			class Student extends Person {
				constructor(name, age, xuehao) { //实例初始化
					// ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor at new Student
					super(name, age); //写到this前边,并且调用
					// super调用本质上是调用父类的constructor函数，传递实参,父类的constructor函数中this是子类的实例（学员）
					// 增加私有属性
					this.xuehao = xuehao;
				}
				
				// 公有
				xiezuoye() {
					console.log("写作业")
				}
			}
			let stu1 = new Student("swk", 500, '1234');
			console.log(stu1);
			
			stu1.xiezuoye();
			stu1.say();
		</script>
	</body>
</html>
